package com.bxmdm.camunda;

import cn.hutool.json.JSONUtil;
import java.util.Map;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.delegate.TaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class CamundaListen {

	@Autowired
	private TaskService taskService;


//	JavaDelegate delegateTest1() {
//		return execution -> {
//			Map<String, Object> variables = execution.getVariables();
//			Map<String, Object> variablesLocal = execution.getVariablesLocal();
//			System.out.println("variables:\n"+JSONUtil.toJsonPrettyStr(variables));
//			System.out.println("variablesLocal:\n"+JSONUtil.toJsonPrettyStr(variablesLocal));
//		};
//	}

	@Bean("delegateTest1")
	TaskListener t21() {
		return delegateTask -> {
			DelegateExecution execution = delegateTask.getExecution();
			Map<String, Object> variables = execution.getVariables();
			Map<String, Object> variablesLocal = execution.getVariablesLocal();
			System.out.println("variables:\n"+JSONUtil.toJsonPrettyStr(variables));
			System.out.println("variablesLocal:\n"+JSONUtil.toJsonPrettyStr(variablesLocal));
		};
	}



}
